package com.lemon.swing;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class MyProgressBar extends JFrame {

	private static final long serialVersionUID = -5941647728179434703L;
	private GridLayout gridLayout = new GridLayout(0,1);
	private int height = 100;
	
	public MyProgressBar(String title){
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(gridLayout);
		this.setResizable(false);
		this.setTitle(title);
	}
	
	public void initProgressBar(String title,int total){
		JProgressBar progressBar = new JProgressBar();
		progressBar.setStringPainted(true);
		progressBar.setIndeterminate(false);
		progressBar.setString(title);
		progressBar.setMaximum(total);
		this.getContentPane().add(progressBar);
		gridLayout.setRows(gridLayout.getRows()+1);
		this.setSize(800,this.getHeight()+height);
		this.setLocationRelativeTo(null);
	}
	
	public void showProgress(){
		this.setVisible(true);
	}
	
	public void close(){
		this.dispose();
	}
	
	public void updateValue(int index,int progress){
		JProgressBar progressBar = (JProgressBar)this.getContentPane().getComponent(index);
		progressBar.setValue(progress);
	}
}
